home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / inject / actflag.c next >
Encoding:
C/C++ Source or Header  |  1992-12-30  |  2.3 KB  |  117 lines

  1. /*
  2.  * actflag group-list - compute overriding active file flag for groups
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include "news.h"
  9. #include "config.h"
  10. #include "active.h"
  11.  
  12. /* flag field values */
  13. #define FLAGOKAY 'y'        /* ordinary unmoderated group */
  14. #define FLAGBAD 'n'        /* unmoderated but locally-restricted group */
  15. #define FLAGMOD 'm'        /* moderated group */
  16. #define FLAGNEVER 'x'        /* unwanted group: don't file in this one */
  17. #define FLAGGOTO '='        /* see another group (following) instead */
  18.  
  19. /* imports */
  20. extern int optind;
  21. extern char *optarg;
  22.  
  23. /* exports */
  24. char *progname = "";
  25. int debug;
  26.  
  27. /* forwards */
  28. char *actflag();
  29.  
  30. /*
  31.  * main - parse arguments and handle options
  32.  */
  33. main(argc, argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.     int c, errflg = 0;
  38.  
  39.     if (argc > 0)
  40.         progname = argv[0];
  41.     while ((c = getopt(argc, argv, "d")) != EOF)
  42.         switch (c) {
  43.         case 'd':
  44.             ++debug;
  45.             break;
  46.         default:
  47.             errflg++;
  48.             break;
  49.         }
  50.     if (errflg || optind != argc - 1) {
  51.         (void) fprintf(stderr, "usage: %s [-d] grouplist\n", progname);
  52.         exit(2);
  53.     }
  54.     (void) fputs(actflag(argv[optind]), stdout);
  55.     (void) putchar('\n');
  56.     exit(0);
  57. }
  58.  
  59. /*
  60.  * actflag - compute dominant active file flag for a list of newsgroups
  61.  */
  62. char *
  63. actflag(ngs)
  64. register char *ngs;
  65. {
  66.     register char *comma, *flagp, *status = strsave(""), *nlp;
  67.     char *actent;
  68.  
  69.     actread();
  70.     /* quit early if we find a moderated group */
  71.     for (; ngs != NULL && *status != FLAGMOD; ngs = comma) {
  72.         comma = strchr(ngs, NGSEP);
  73.         if (comma != NULL)
  74.             *comma = '\0';        /* will be restored below */
  75.  
  76.         actent = actlook(ngs);
  77.         if (actent != NULL) {        /* group known locally? */
  78.             flagp = findflag(actent);
  79.             switch (*flagp) {
  80.             case FLAGBAD:
  81.             case FLAGNEVER:
  82.             case FLAGMOD:
  83.                 switch (*status) {
  84.                 case FLAGBAD:
  85.                 case FLAGNEVER:
  86.                     break;
  87.                 default:
  88.                     free(status);
  89.                     nlp = strchr(flagp, '\n');
  90.                     if (nlp != NULL)
  91.                         *nlp = '\0';
  92.                     status = str3save(flagp, " ", ngs);
  93.                     if (nlp != NULL)
  94.                         *nlp = '\n';
  95.                     break;
  96.                 }
  97.                 break;
  98.             case FLAGOKAY:
  99.             default:
  100.                 switch (*status) {
  101.                 case FLAGBAD:
  102.                 case FLAGNEVER:
  103.                     break;
  104.                 default:
  105.                     free(status);
  106.                     status = strsave("y");
  107.                     break;
  108.                 }
  109.                 break;
  110.             }
  111.         }
  112.         if (comma != NULL)
  113.             *comma++ = NGSEP;    /* step past comma */
  114.     }
  115.     return status;
  116. }
  117.